package  
{
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	/**
	 * ...
	 * @author jun
	 */
	public class MMBasicWindow extends MMInteractive
	{
		private var _background:DisplayObject;
		private var _titlePane:MMInteractive;
		private var _contentPane:Sprite;
		
		private var _canDrag:Boolean = false;
		
		protected var _width:Number = 0;
		protected var _height:Number = 0;
		public function MMBasicWindow() 
		{
			super();
			width = 10;
			height = 10;
			mouseChildren = true;
			
		}
		
		/* INTERFACE IComponent */
		
		override public function onShow():void 
		{
			super.onShow();
			if (!this.parent && this.stage == null )
			{
				MangMeiMgr.root.addChild(this);
			}
			
		}
		
		override public function onInit():void 
		{
			super.onInit();
			if (_background == null)
			{
				drawBackground();
			}
			
		}
		
		protected function drawBackground(color:uint=0xB53D09,alpha:Number=.8):void 
		{
			graphics.clear();
			graphics.beginFill(color,alpha);
			graphics.drawRoundRect(0, 0, width, height, 10, 10);
			graphics.endFill();
		}
		
		override public function onHide():void 
		{
			super.onHide();
			if (this.parent)
			{
				parent.removeChild(this);
			}
		}
		
		override public function updateData():void 
		{
			
		}
		
		override public function regResource():void 
		{
			
		}
		
		public function toBack():void
		{
			if (this.parent)
			{
				this.parent.setChildIndex(this, 0);
			}
		}
		
		public function toFront():void
		{
			if (this.parent)
			{
				this.parent.setChildIndex(this, this.parent.numChildren-1);
			}
		}
		
		public function set canDrag(value:Boolean):void
		{
			_canDrag = value;
			if (value)
			{
				onMouseDown = onMouseDownHander;
				onMouseUp = onMouseUpHandler;
				
			}else
			{
				onMouseDown = null;
				onMouseUp = null;
			}
		}
		
		private function onMouseUpHandler(e:MouseEvent):void 
		{
			if (_canDrag)
			{
				this.stopDrag();
			}
		}
		
		private function onMouseDownHander(e:MouseEvent):void 
		{
			if (_canDrag)
			{
				this.startDrag();
			}
		}
		
		override public function get width():Number { return _width; }
		
		override public function set width(value:Number):void 
		{
			//super.width = value;
			_width = value;
		}
		
		override public function get height():Number { return _height; }
		
		override public function set height(value:Number):void 
		{
			//super.height = value;
			_height = value;
		}
		
		
	}

}